package com.vichat.user.threads;
import com.vichat.common.constant.GlobalConstant;
import com.vichat.common.signal.CmdUtil;
import com.vichat.common.vo.PageFilter;
import com.vichat.common.vo.SysMsg;
import com.vichat.user.entity.UserBasic;
import com.vichat.user.service.IUserService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * Created by ranjx on 2018/04/08.
 */
public class RefreshUserThread implements Runnable {
    private static Logger logger = LoggerFactory.getLogger(RefreshUserThread.class);
    private IUserService userService;
    private long partyId;
    private String refreshType;

    public RefreshUserThread(IUserService userService, long partyId, String refreshType) {
        this.userService = userService;
        this.partyId = partyId;
        this.refreshType = refreshType;
    }

    @Override
    public void run() {
        try {
            UserBasic queryBean = new UserBasic();
//            queryBean.setUserType(GlobalConstant.USER_TYPE_5);
            queryBean.setPartyId(partyId);
            List<UserBasic> userBasics = userService.queryUserBasics(queryBean, PageFilter.getMaxPageFilter(),false);
            if(!userBasics.isEmpty()){
                for (UserBasic user : userBasics) {
                    if (StringUtils.equals(refreshType, GlobalConstant.REFRESH_TYPE_USER)) {
                        //刷新用户
                        CmdUtil.sendImMsg(10000, user.getUid(), 0, GlobalConstant.IMS_MSG_TYPE_10008, "");
                    }
                    if (StringUtils.equals(refreshType, GlobalConstant.REFRESH_TYPE_ORG)) {
                        CmdUtil.sendImMsg(10000, user.getUid(), 0, GlobalConstant.IMS_MSG_TYPE_10010, "");
                    }
                }
            }
        } catch (Exception e) {
            logger.error("发送消息失败>>>>>>" + e.getMessage(), e);
        }
    }

}
